package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.DialogEditTeamGroupBinding
import com.lxj.xpopup.core.CenterPopupView
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.clickWithTrigger


class EditTeamGroupDialog(
    context: Context,
    private val content: String = "",
    private val onEdit: (content: String) -> Unit,
) : CenterPopupView(context) {

    private lateinit var binding: DialogEditTeamGroupBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_edit_team_group
    }

    override fun onCreate() {
        super.onCreate()
        binding = DialogEditTeamGroupBinding.bind(popupImplView)

        binding.etContent.setText(content)

        binding.tvCancel.click { dismiss() }
        binding.tvConfirm.clickWithTrigger {
            val content = binding.etContent.text.toString().trim()
            if (content.isEmpty()){
                toast("请输入分组名称")
                return@clickWithTrigger
            }
            dismiss()
            onEdit(content)
        }
    }

}